#yum -y install wget
#wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
yum -y install ansible
echo '[yang]' >> /etc/ansible/hosts
A=`hostname -I | awk -F "." 'BEGIN{OFS="."} {print $1,$2,$3}'`
for i in {50，60，70，80}
do
ping -c1 $A.$i &>/dev/null
if [ $? -eq 0 ]
then
echo $A.$i >> /etc/ansible/hosts
fi
done
bash 自动分发公私钥.sh
cat >> /root/pass.sh <<EOF
A=\`grep pass /var/log/mysqld.log | awk -F ": " 'NR==1{print \$NF}'\`
mysqladmin -uroot -p\$A password "1"
EOF
cat >> /root/mysql.yml <<EOF
---
- name: mysql
  hosts: all
  tasks:
  - name: copy mysql软件包
    copy: src=/root/MYSQL-5.7_RPM安装 dest=/root
  - name: 安装mysql
    shell: yum -y install /root/MYSQL-5.7_RPM安装/*
  - name: 启动mysql
    shell: systemctl start mysqld
  - name: 修改配置文件:支持中文
    shell: echo "character_set_server = utf8" >> /etc/my.cnf
#  - name: 修改配置文件:跳过密码
#    shell: echo "skip-grant-tables" >> /etc/my.cnf
  - name: 修改配置文件:简易密码
    shell: echo "validate_password=off" >> /etc/my.cnf
  - name: 重启mysql服务
    shell: systemctl restart mysqld
  - name: 密码脚本
    copy: src=/root/pass.sh dest=/root
  - name: 执行密码脚本
    shell: bash /root/pass.sh
EOF
ansible-playbook mysql.yml
